#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10;
int a[N],T,n;
void work1(){
    ll tot=1,ans=0;
    for(int i=1;i<n;i++) tot<<=1;
    for(int p=0;p<tot;p++){
        ll tmp=0;
        for(int i=1;i<=n;i++){
            for(int j=n-i+1;j<n;j++){
                if(((p>>(n-i))&(p>>(j)))&&a[i]==a[j]) tmp+=a[i];
                // cout<<ans<<endl;
            }
        }
        ans=max(ans,tmp);
    }
    printf("%lld\n",ans);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        // clear!!!!!!!!!!
        // long long!!!!!!!!!
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        work1();
    }
    return 0;
}